#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * DNS Address Record Structure
 *      Represents a DNS address (A) record.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;
using namespace System::Net;

namespace Adaptive
{
	namespace Network
	{
		namespace Dns
		{
			/// <summary>
			/// Represents a DNS address (A) record.
			/// </summary>
			public value struct DnsAddressRecord
			{
			internal:
				/// <summary>
				/// Initializes a new instance of the class from the unmanaged record.
				/// </summary>
				/// <param name="record"> A pointer to a DNS_RECORD structure whose contents are to be copied.</param>
				DnsAddressRecord(DNS_RECORD* record)
				{
					DWORD ipValue = 0;

					if ((record == NULL) || (record->wType != DNS_TYPE_A))
						IP = nullptr;
					else
					{
						ipValue = (DWORD)record->Data.A.IpAddress;
						try
						{
							IP = gcnew IPAddress( ((__int64)ipValue) );
						}
						catch(Exception^ ex)
						{
							Console::WriteLine(ex->Message);
							IP = nullptr;
						}
					}
				}
			public:

				/// <summary>
				/// Gets the IP address for the record.
				/// </summary>
				/// <value>
				/// The reported IP address, in the form of an <see cref="IPAddress"/>.
				/// </value>
				IPAddress^	IP;

			private:
				/// <summary>
				/// Static constructor.
				/// </summary>
				static DnsAddressRecord()
				{
				}

			};
		}
	}
}
